package com.css.dzj.dzjportal.modules.changepwd.controller;

import com.css.dzj.dzjportal.common.util.R;
import com.css.dzj.dzjportal.common.util.userinfo.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 修改密码
 * @Author WT
 * @Date 2020/7/21
 */
@RestController
@RequestMapping("/changePwd")
public class ChangeController {

    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    HttpServletRequest request;

    @PostMapping("/update")
    public R update(@RequestParam String oldPassword,
                    @RequestParam String password,
                    @RequestParam String userId){
        try {
            if(StringUtils.isEmpty(password) ||StringUtils.isEmpty(userId) || StringUtils.isEmpty(oldPassword)) {
                return R.error("参数为空！");
            }
            userInfoService.updatePassword(oldPassword,password,userId,request);
            return R.ok();
        } catch(Exception e) {
            e.printStackTrace();
            return R.error(e.getMessage());
        }
    }
}
